import Vue from 'vue'
import Axios from 'axios'

export default {
  install : function(Vue,domain) {

    Vue.prototype.$get = function (url, data) {
      var p = new Promise(function (resolve, reject) {
        Axios.get(domain + url, {params : data}).then(function (data) {
            var data = data.data;
            if (data.code == 0) {
              resolve(data.data);
            } else {
              alert(data.msg);
              reject();
            }
          },
          function (err) {
            alert(err);
            reject();
          });
      });
      return p;
    };


    Vue.prototype.$post = function(url,data){
      var that = this;
      var p = new Promise(function(resolve,reject){
        Axios.post(domain + url, data).then(function (data) {
            var data = data.data;
            if (data.code == 0) {
              resolve(data.data);
            } else {
              alert(data.msg);
              reject();
            }
          },
          function (err) {
            alert(err);
            reject();
          });
      });
      return p;
    }


  }
}
